import java.io.File

/**
 *  @AUTHOR zhangxiaofan07
 *  @CREATE 2022-03-01 11:47
 */

fun batchModifyFileName(
    dirStr: String,
    fileList: List<File>,
    oldStr: String,
    newStr: String = "",
    onResult: (code: Int, fileNameList: List<String>) -> Unit
) {
    val fileNameList = ArrayList<String>()

    fileList.forEach {
        println(it.absoluteFile)
        val oldFileName = it.name
        if (!oldFileName.contains(oldStr)) {
            return
        }
        val newFileName = oldFileName.replace(oldStr, newStr)

        if (!it.renameTo(File(dirStr, newFileName))) {
            fileNameList.add(oldFileName)
        }
        onResult(fileNameList.size, fileNameList)
    }
}

